import {covertTheme} from "../../utils/style.uitls";
import {deepMerge} from "../../utils/utils.utils";
// index.js
Component({
    options: {
        multipleSlots: true,
        addGlobalClass: true,
    },
    lifetimes: {
        created() {},
        attached() {
            const that = this;
            that.setConfigStyle();
            that.checkIfTabBarPage();
        },
        ready() {
            const that = this;
            that.setConfigStyle();
        },
    },
    /**
     * 组件的初始数据
     */
    data: {
        ifTabBarPage: true,
        rootStyle: "",
    },
    /**
     * 组件的属性列表
     */
    properties: {
        navBar: {
            type: Object,
            value: {}
        },
        pageConfig: {
            type: Object,
            value: {}
        },
        theme: {
            type: Object,
            value: {}
        }
    },
    observers: {
        'theme'(theme) {
            this.setConfigStyle(theme);
        }
    },
    /**
     * 组件的方法列表
     */
    methods: {
        setConfigStyle(theme) {
            const defaultTheme = this.data.config.theme;
            const deepTheme = deepMerge(defaultTheme, theme);
            const style = covertTheme(deepTheme);
            this.setData({
                "rootStyle": style
            });
        },
        checkIfTabBarPage() {
            const that = this;
            const tabBar = this.data.config.tabBar;
            let pages = getCurrentPages();
            let currPage = null;
            if (pages.length) {
                // 获取当前页面的前以页面的对象
                currPage = pages[pages.length - 1];
                // 获取当前页面的前一页面的路由
                let route = currPage.route;
                const ifTab = tabBar.some(item => item.pagePath.indexOf(route) > -1 );
                that.setData({
                    ifTabBarPage: ifTab
                })
                let show = (that.data.config.showTabBarAllPage || that.data.ifTabBarPage) && !that.data.config.useDefaultTabBar;
            }
        }
    }
})